package com.foreveross.chameleon.parser;

import android.util.Log;

import com.foreveross.pojo.CubeContent;
import com.foreveross.pojo.CubeModule;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class CubeContentParser {
	
	public CubeContent parser(String json) {
		Log.v("json", json);
		GsonBuilder builder = new GsonBuilder();
		Gson gson = builder.create();
		CubeContent result = gson.fromJson(json, CubeContent.class);
		if (result.getModules() != null) {
			for (CubeModule each : result.getModules()) {
				if (each.getLocal() != null) {//判断是否原生模块
					each.setModuleType(CubeModule.INSTALLED);
				} else if (each.getModuleType() == -1) {
					each.setModuleType(CubeModule.UNINSTALL);
				} else if ( each.getModuleType() == CubeModule.INSTALLING ){
					each.setModuleType(CubeModule.UNINSTALL);
				} else if(each.getModuleType() == CubeModule.UPGRADING ){
					each.setModuleType(CubeModule.INSTALLED);
				} else if(each.getModuleType() == CubeModule.DELETING ){
					each.setModuleType(CubeModule.INSTALLED);
				}
			}
		}
		return result;
	}
}
